# from time import sleep
# #
# #
# # # 生成器 - 数据生产者
# # def countdown_gen(n, consumer):
# #     consumer.send(None)
# #     while n > 0:
# #         consumer.send(n)
# #         n -= 1
# #     consumer.send(None)
# #
# # # 协程 - 数据消费者
# # def countdown_con():
# #     while True:
# #         n = yield
# #         if n:
# #             print(f'Countdown {n}')
# #             sleep(1)
# #         else:
# #             print('Countdown Over!')
# #
# #
# # def main():
# #     countdown_gen(5, countdown_con())
# # if __name__ == '__main__':
# #     main()
import asyncio


@asyncio.coroutine
def countdown(name, n):
    while n > 0:
        print(f'Countdown[{name}]: {n}')
        yield from asyncio.sleep(1)
        n -= 1


def main():
    loop = asyncio.get_event_loop()
    tasks = [
        countdown("A", 10), countdown("B", 5),
    ]
    loop.run_until_complete(asyncio.wait(tasks))
    loop.close()


if __name__ == '__main__':
    main()